home *** CD-ROM | disk | FTP | other *** search
/ Aminet 1 (Walnut Creek) / Aminet - June 1993 [Walnut Creek].iso / usenet / sources / volume89 / languags / zc.1 < prev    next >
Text File  |  1989-03-08  |  37KB  |  1,444 lines

  1. Path: xanth!nic.MR.NET!csd4.milw.wisc.edu!mailrus!bbn!ulowell!page
  2. From: page@swan.ulowell.edu (Bob Page)
  3. Newsgroups: comp.sources.amiga
  4. Subject: v89i028:  zc - c compiler, Part01/04
  5. Message-ID: <12042@swan.ulowell.edu>
  6. Date: 8 Mar 89 03:02:11 GMT
  7. Organization: University of Lowell, Computer Science Dept.
  8. Lines: 1433
  9. Approved: page@swan.ulowell.edu
  10.  
  11. Submitted-by: monty@brahms.Berkeley.EDU (Joe Montgomery)
  12. Posting-number: Volume 89, Issue 28
  13. Archive-name: languages/zc.1
  14.  
  15. This is zc, a modified version of hcc (the Sozobon-C compiler by
  16. Johann Ruegg) from Fred Fish disk 171.  I have made some minor
  17. modifications to get it to work with A68K and Blink.  Also included is
  18. zcc, a unix-style front end for zc/a68k/blink.
  19.  
  20. #    This is a shell archive.
  21. #    Remove everything above and including the cut line.
  22. #    Then run the rest of the file through sh.
  23. #----cut here-----cut here-----cut here-----cut here----#
  24. #!/bin/sh
  25. # shar:    Shell Archiver
  26. #    Run the following text with /bin/sh to create:
  27. #    bstok.h
  28. #    cookie.h
  29. #    flags.h
  30. #    gen.h
  31. #    nodes.h
  32. #    ops.h
  33. #    param.h
  34. #    sttok.h
  35. #    tok.h
  36. #    tytok.h
  37. #    zc.doc
  38. #    zcc.doc
  39. #    zc.readme
  40. #    zcc.readme
  41. #    makefile
  42. #    zcc.c
  43. # This archive created: Tue Mar  7 21:51:16 1989
  44. cat << \SHAR_EOF > bstok.h
  45. /* Copyright (c) 1988 by Sozobon, Limited.  Author: Johann Ruegg
  46.  *
  47.  * Permission is granted to anyone to use this software for any purpose
  48.  * on any computer system, and to redistribute it freely, with the
  49.  * following restrictions:
  50.  * 1) No charge may be made other than reasonable charges for reproduction.
  51.  * 2) Modified versions must be clearly marked as such.
  52.  * 3) The authors are not responsible for any harmful consequences
  53.  *    of using this software, even if they result from defects in it.
  54.  *
  55.  *    bstok.h
  56.  *
  57.  *    basic token values
  58.  *    (some compilers cant do enums, so use defines)
  59.  */
  60.  
  61. #ifndef ENUMS
  62. #define BADTOK    0
  63. #define ID    1
  64. #define ICON    2
  65. #define FCON    3
  66. #define SCON    4
  67. #define DPARAM    6    /* parameter to #define */
  68. #define EOFTOK    7
  69. #define POSTINC 8    /* DOUBLE '+' is pre-inc */
  70. #define POSTDEC 9    /* DOUBLE '-' is pre-dec */
  71. #define TCONV    10    /* coertion */
  72. #define TSIZEOF 11    /* sizeof(type expr) */
  73. #define NL    12
  74. #define WS    13    /* white space */
  75. #define SCON2    14    /* <string> */
  76. #define PTRDIFF 0x18
  77. #define PTRADD    0x19
  78. #define PTRSUB    0x1a
  79. #define ARROW    0x1b
  80. #define LTEQ    0x1c
  81. #define GTEQ    0x1d
  82. #define NOTEQ    0x1e
  83. #else
  84. enum {
  85.     BADTOK, ID, ICON, FCON, SCON, DPARAM, EOFTOK,
  86.     POSTINC, POSTDEC, TCONV, TSIZEOF, NL, WS, SCON2,
  87.     PTRDIFF, PTRADD, PTRSUB, ARROW, LTEQ, GTEQ, NOTEQ
  88. };
  89. #endif
  90.  
  91. #define ASSIGN    0x100+    /* add to char of op */
  92. #define DOUBLE    0x80+
  93. #define UNARY    0x200+
  94.  
  95. #define STAR    (UNARY '*')    /* used a lot */
  96.  
  97. #define isassign(x)    (x >= 0x100)
  98. SHAR_EOF
  99. cat << \SHAR_EOF > cookie.h
  100. /* Copyright (c) 1988 by Sozobon, Limited.  Author: Johann Ruegg
  101.  *
  102.  * Permission is granted to anyone to use this software for any purpose
  103.  * on any computer system, and to redistribute it freely, with the
  104.  * following restrictions:
  105.  * 1) No charge may be made other than reasonable charges for reproduction.
  106.  * 2) Modified versions must be clearly marked as such.
  107.  * 3) The authors are not responsible for any harmful consequences
  108.  *    of using this software, even if they result from defects in it.
  109.  *
  110.  *    cookie.h
  111.  */
  112.  
  113. /* restrictions on type */
  114.  
  115. #define R_INTEGRAL    1
  116. #define R_FLOATING    2
  117. #define R_POINTER    4
  118. #define R_STRUCT    8
  119. #define R_ARITH        (R_INTEGRAL|R_FLOATING)
  120. #define R_SCALAR    (R_ARITH|R_POINTER)
  121. #define R_ASSN        (R_SCALAR|R_STRUCT)
  122.  
  123. /* cookies */
  124. #define FORSIDE        1
  125. #define FORPUSH        2
  126. #define FORCC        3
  127. #define FORIMA        4
  128. #define FORADR        5
  129. #define FORINIT        6
  130. #define IND0        7
  131. #define RETSTRU        8
  132.  
  133. /* eval flags derived from cookie */
  134. #define NOVAL_OK    1    /* value is optional */
  135. #define CC_OK        2    /* just setting cond. codes okay */
  136. #define IMMA_OK        4    /* immediate OREG is okay */
  137. SHAR_EOF
  138. cat << \SHAR_EOF > flags.h
  139. /* Copyright (c) 1988 by Sozobon, Limited.  Author: Johann Ruegg
  140.  *
  141.  * Permission is granted to anyone to use this software for any purpose
  142.  * on any computer system, and to redistribute it freely, with the
  143.  * following restrictions:
  144.  * 1) No charge may be made other than reasonable charges for reproduction.
  145.  * 2) Modified versions must be clearly marked as such.
  146.  * 3) The authors are not responsible for any harmful consequences
  147.  *    of using this software, even if they result from defects in it.
  148.  *
  149.  *    flags.h
  150.  *
  151.  *    token or e_flags flags
  152.  */
  153.  
  154. #define CAN_U    2    /* can be unary op */
  155. #define CAN_AS    4    /* can be op-assign */
  156. #define SPECIAL 8    /* special token beginner ("'/*) */
  157. #define SEE_U    0x10    /* for ICON */
  158. #define SEE_L    0x20    /* for ICON */
  159. #define C_NOT_A 0x40    /* commutative but not associative */
  160. #define C_AND_A 0x80    /* commutative and associative */
  161. #define IMMEDID    0x100    /* Ptr to XXX ID which is really
  162.                 Array of XXX or Fun ret XXX */
  163. #define CHILDNM    0x200    /* my name is my (left) child's name */
  164. #define SIDE_CC 0x400    /* cc set as side effect of op. */
  165. #define RCHILDNM 0x800    /* my name is my (right) child's name */
  166. SHAR_EOF
  167. cat << \SHAR_EOF > gen.h
  168. /* Copyright (c) 1988 by Sozobon, Limited.  Author: Johann Ruegg
  169.  *
  170.  * Permission is granted to anyone to use this software for any purpose
  171.  * on any computer system, and to redistribute it freely, with the
  172.  * following restrictions:
  173.  * 1) No charge may be made other than reasonable charges for reproduction.
  174.  * 2) Modified versions must be clearly marked as such.
  175.  * 3) The authors are not responsible for any harmful consequences
  176.  *    of using this software, even if they result from defects in it.
  177.  *
  178.  *    gen.h
  179.  */
  180.  
  181. #include "cookie.h"
  182.  
  183. /* parameters for case */
  184. #define C_SIMPLE    8    /* use simple if n <= this */
  185. #define C_RATIO        3    /* use table if max-min/n <= this */
  186.  
  187. /* branch types */
  188. /* designed so that pairs (i,i+1) with odd i represent opposites */
  189. #define B_EQ    1
  190. #define B_NE    2
  191. #define B_LT    3
  192. #define B_GE    4
  193. #define B_LE    5
  194. #define B_GT    6
  195. #define B_YES    7
  196. #define B_NO    8
  197. #define B_ULT    9
  198. #define B_UGE    10
  199. #define B_ULE    11
  200. #define B_UGT    12
  201.  
  202. /* derived nodes */
  203. /* re-use stmt keywords for now */
  204. #ifndef ENUMS
  205. #define ONAME    'a'
  206. #define OREG    'b'
  207. #define REGVAR    'c'
  208. #define PUSHER    'd'
  209. #define CMPBR    'e'
  210. #define FIELDAS    'f'
  211. #else
  212. enum {
  213.     ONAME = 'a', OREG, REGVAR, PUSHER, CMPBR, FIELDAS
  214. };
  215. #endif
  216.  
  217. #define BR_TOK    'i'
  218.  
  219. /* evaluation order values */
  220. #define EV_NONE        0
  221. #define EV_LEFT        1
  222. #define EV_RIGHT    2
  223. #define EV_LR        3
  224. #define EV_RL        4
  225. #define EV_LRSEP    5    /* left then right, but seperate */
  226. SHAR_EOF
  227. cat << \SHAR_EOF > nodes.h
  228. /* Copyright (c) 1988 by Sozobon, Limited.  Author: Johann Ruegg
  229.  *
  230.  * Permission is granted to anyone to use this software for any purpose
  231.  * on any computer system, and to redistribute it freely, with the
  232.  * following restrictions:
  233.  * 1) No charge may be made other than reasonable charges for reproduction.
  234.  * 2) Modified versions must be clearly marked as such.
  235.  * 3) The authors are not responsible for any harmful consequences
  236.  *    of using this software, even if they result from defects in it.
  237.  *
  238.  *    nodes.h
  239.  */
  240.  
  241. /*
  242.  *    stuff common to all nodes
  243.  */
  244. #define COMMON    int cflags;    \
  245.         int fill;    \
  246.         union node *left;    \
  247.         union node *right;    \
  248.         union node *tptr;    \
  249.         union node *nm_ext;    \
  250.         char cname[NMSIZE]
  251.  
  252. #define n_flags e.cflags
  253. #define n_left    e.left
  254. #define n_next    e.left
  255. #define n_right e.right
  256. #define n_tptr    e.tptr
  257. #define n_nmx    e.nm_ext
  258. #define n_name    e.cname
  259.  
  260. /*
  261.  *    expression (and symbol table) node
  262.  */
  263. struct enode {
  264.     COMMON;
  265.     int    token;        /* must be same place as tnode */
  266.     int    eflags;
  267.     char    etype;        /* type of node */
  268.     char    sc;
  269.     char    eprec;
  270.     char    rno;
  271.     union {
  272.         long    vival;
  273.         long    voffs;
  274.         double    vfval;
  275.     } vu;
  276.     char    fldw, fldof;        /* use if cant do fields */
  277. /*    unsigned    fldw:6, fldof:6;    /* use fields just so
  278.                         we know fields work */
  279. };
  280.  
  281. #define e_token e.token
  282. #define e_flags e.eflags
  283. #define e_prec    e.eprec
  284. #define e_rno    e.rno
  285. #define e_type    e.etype
  286. #define e_ival    e.vu.vival
  287. #define e_offs    e.vu.voffs
  288. #define e_fval    e.vu.vfval
  289. #define e_sc    e.sc
  290. #define e_fldw    e.fldw
  291. #define e_fldo    e.fldof
  292.  
  293. /* for e_flags values, see tok.h */
  294.  
  295. /* values for e_type */
  296.  
  297. #define E_LEAF    0    /* no descendants */
  298. #define E_UNARY 1    /* left node is expr, no right node */
  299. #define E_BIN    2    /* left and right are expr */
  300. #define E_SPEC    3    /* special '(', '[', '.', '->', ... */
  301.  
  302. /*
  303.  * code generation node
  304.  */
  305. struct gnode {
  306.     COMMON;
  307.     int    token;
  308.     int    eflags;
  309.     char    etype;
  310.     char    sc;
  311. /* all of above fields must match first fields in enode! */
  312.  
  313.     char    needs;        /* registers needed */
  314.     char    grno;        /* register used in ret value */
  315.     char    basety;     /* type FLOAT, UNS, INT or AGREG */
  316.     char    basesz;     /* size 1,2,4 or 3 -> see bsize */
  317.     char    gr1, gr2;
  318.     char    *betwc;     /* code for between L and R */
  319.     long    goffs;        /* offsets for OREG, ONAME */
  320.     union gu {
  321.         long    bsize;        /* AGREG size or misc. */
  322.         struct {
  323. /*            int    gfldw:6, gfldo:6;    /* field info */
  324.             char    gfldw, gfldo;    /* use if no fields */
  325.         } gfl;
  326.     } gu;
  327. };
  328.  
  329. #define g_token g.token
  330. #define g_flags g.eflags
  331. #define g_type    g.etype
  332. #define g_sc    g.sc
  333. #define g_needs g.needs
  334. #define g_rno    g.grno
  335. #define g_offs    g.goffs
  336. #define g_betw    g.betwc
  337. #define g_ty    g.basety
  338. #define g_sz    g.basesz
  339. #define g_code    g.tptr
  340. #define g_bsize g.gu.bsize
  341. #define g_fldw    g.gu.gfl.gfldw
  342. #define g_fldo    g.gu.gfl.gfldo
  343. #define g_r1    g.gr1
  344. #define g_r2    g.gr2
  345.  
  346. /* types of operands -- ordered in cast strength order */
  347. #define ET_S    1    /* signed integer */
  348. #define ET_U    2    /* unsigned integer */
  349. #define ET_F    3    /* float or double */
  350. #define ET_A    4    /* aggregate */
  351.  
  352. /*
  353.  *    type list node
  354.  */
  355. struct tnode {
  356.     COMMON;
  357.     int    token;        /* must be same place as enode */
  358.     int    tflags;
  359.     char    aln;        /* alignment needed */
  360.     long    tsize;
  361. };
  362.  
  363. #define t_token t.token
  364. #define t_flags t.tflags
  365. #define t_size    t.tsize
  366. #define t_aln    t.aln
  367.  
  368. /*
  369.  *    name extension node
  370.  */
  371. struct nmext {
  372.     COMMON;
  373.     char nmx[NMXSIZE-NMSIZE];    /* name extension (with name)*/
  374. };
  375.  
  376. #define x_nm    x.nmx
  377.  
  378. /*
  379.  *    block info node
  380.  */
  381. struct bnode {
  382.     COMMON;
  383.     union node *syms;
  384.     union node *tags;
  385.     int    regs;        /* reg alloc mask */
  386.     long    lsize;        /* size of locals */
  387.     int    tmsize;     /* max tmps used for 1 expr */
  388. };
  389.  
  390. #define b_syms    b.syms
  391. #define b_tags    b.tags
  392. #define b_regs    b.regs
  393. #define b_size    b.lsize
  394. #define b_tsize b.tmsize
  395.  
  396. /*
  397.  *    node to hold case for switch generation
  398.  */
  399. struct cnode {
  400.     COMMON;
  401.     int    c_value;    /* value for case */
  402.     int    c_label;    /* case label or label label */
  403.     int    c_def;        /* label defined */
  404. };
  405.  
  406. #define c_defined c.c_def
  407. #define c_casev c.c_value
  408. #define c_casel c.c_label
  409.  
  410. union node {
  411.     struct enode e;
  412.     struct tnode t;
  413.     struct nmext x;
  414.     struct bnode b;
  415.     struct cnode c;
  416.     struct gnode g;
  417. };
  418.  
  419. typedef union node NODE;
  420. typedef NODE *NODEP;
  421.  
  422. /* defines for n_flags */
  423.  
  424. #define N_BRKPR 1    /* break printnode recursion */
  425. #define N_COPYT 2    /* tptr is a copy */
  426. #define N_ISFREE 4    /* node is on free list (error check) */
  427.  
  428. NODEP allocnode();
  429. SHAR_EOF
  430. cat << \SHAR_EOF > ops.h
  431. /* Copyright (c) 1988 by Sozobon, Limited.  Author: Johann Ruegg
  432.  *
  433.  * Permission is granted to anyone to use this software for any purpose
  434.  * on any computer system, and to redistribute it freely, with the
  435.  * following restrictions:
  436.  * 1) No charge may be made other than reasonable charges for reproduction.
  437.  * 2) Modified versions must be clearly marked as such.
  438.  * 3) The authors are not responsible for any harmful consequences
  439.  *    of using this software, even if they result from defects in it.
  440.  *
  441.  *    ops.h
  442.  *
  443.  *    defines of allowed operands
  444.  *    'E' means Dreg or OREG or ONAME or (if on left) ICON
  445.  *    'Q' means ICON which is 1 to 8
  446.  *    ONE means ICON which is 1
  447.  */
  448.  
  449. #define DOPD    1
  450. #define AOPD    2
  451. #define MOPD    4
  452. #define IOPD    8
  453.  
  454. #define DOPA    0x10
  455. #define AOPA    0x20
  456. #define MOPA    0x40
  457. #define IOPA    0x80
  458.  
  459. #define DOPM    0x100
  460. #define AOPM    0x200
  461. #define MOPM    0x400
  462. #define IOPM    0x800
  463.  
  464. #define QOPD    0x1000
  465. #define ONEOPM    0x2000
  466. #define ASSOC    0x4000
  467.  
  468. #define EOPD    (DOPD|MOPD|IOPD)
  469. #define DOPE    (DOPD|DOPM)
  470. #define IOPE    (IOPD|IOPM)
  471. #define EOPA    (DOPA|MOPA|IOPA)
  472. SHAR_EOF
  473. cat << \SHAR_EOF > param.h
  474. /* Copyright (c) 1988 by Sozobon, Limited.  Author: Johann Ruegg
  475.  *
  476.  * Permission is granted to anyone to use this software for any purpose
  477.  * on any computer system, and to redistribute it freely, with the
  478.  * following restrictions:
  479.  * 1) No charge may be made other than reasonable charges for reproduction.
  480.  * 2) Modified versions must be clearly marked as such.
  481.  * 3) The authors are not responsible for any harmful consequences
  482.  *    of using this software, even if they result from defects in it.
  483.  *
  484.  *    param.h
  485.  *
  486.  *    basic parameters
  487.  */
  488.  
  489. #ifndef MMCC
  490. #define MMCC    0
  491. #endif
  492.  
  493. #ifndef CC68
  494. #define CC68    0
  495. #endif
  496.  
  497. #ifndef dLibs
  498. #define dLibs    0
  499. #endif
  500.  
  501. #undef NULL
  502. #define NULL 0L
  503.  
  504. #define ENUMS    1    /* define if host compiler can do enums */
  505. #define DEBUG    1
  506.  
  507. #define NHASH    32
  508.  
  509. #define ROPEN    "r"
  510. #define WOPEN    "w"
  511. #define FLTFORM "%.3g"
  512.  
  513. #define MAXSTR    256
  514. #define MAXINCL 10
  515. #define NMSIZE    12    /* must be at least 12 */
  516. #define NMXSIZE    32
  517.  
  518. /* sizes of basic types */
  519. #ifndef NOLONGS
  520. #define SIZE_C    1    /* char */
  521. #define SIZE_I    2    /* int */
  522. #define SIZE_S    2    /* short */
  523. #define SIZE_L    4    /* long */
  524. #define SIZE_U    2    /* unsigned */
  525. #define SIZE_F    4    /* float */
  526. #define SIZE_D    4    /* double */
  527. #define SIZE_P    4    /* pointer */
  528. #define MAXINT    0x7fffL
  529. #define MININT    -0x8000
  530. #define MAXUNS    0xffffL
  531. #else
  532. #define SIZE_C    1    /* char */
  533. #define SIZE_I    4    /* int */
  534. #define SIZE_S    2    /* short */
  535. #define SIZE_L    4    /* long */
  536. #define SIZE_U    4    /* unsigned */
  537. #define SIZE_F    4    /* float */
  538. #define SIZE_D    4    /* double */
  539. #define SIZE_P    4    /* pointer */
  540. #define MAXINT    0x7fffffff
  541. #endif
  542.  
  543. /* alignment requirements */
  544. #define ALN_C    0    /* char */
  545. #define ALN_I    1    /* int */
  546. #define ALN_S    1    /* short */
  547. #define ALN_L    1    /* long */
  548. #define ALN_U    1    /* unsigned */
  549. #define ALN_F    1    /* float */
  550. #define ALN_D    1    /* double */
  551. #define ALN_P    1    /* pointer */
  552.  
  553. #define STACKALN 1
  554.  
  555. /* usage for registers */
  556. #define DRV_START    3
  557. #define DRV_END        7
  558. #define AREG        8
  559. #define ARV_START    AREG+3
  560. #define ARV_END        AREG+5
  561.  
  562. /* definition of stack frame */
  563. #define ARG_BASE    8
  564. #define LOC_BASE    0
  565.  
  566. /* need for own buffers (ALCYON hack ) ? */
  567. #define NEEDBUF        0
  568.  
  569. SHAR_EOF
  570. cat << \SHAR_EOF > sttok.h
  571. /* Copyright (c) 1988 by Sozobon, Limited.  Author: Johann Ruegg
  572.  *
  573.  * Permission is granted to anyone to use this software for any purpose
  574.  * on any computer system, and to redistribute it freely, with the
  575.  * following restrictions:
  576.  * 1) No charge may be made other than reasonable charges for reproduction.
  577.  * 2) Modified versions must be clearly marked as such.
  578.  * 3) The authors are not responsible for any harmful consequences
  579.  *    of using this software, even if they result from defects in it.
  580.  *
  581.  *    sttok.h
  582.  *
  583.  *    statement keyword tokens
  584.  */
  585.  
  586. #ifndef ENUMS
  587. #define K_GOTO        'a'
  588. #define K_RETURN    'b'
  589. #define K_BREAK        'c'
  590. #define K_CONTINUE    'd'
  591.  
  592. #define K_IF        'e'
  593. #define K_ELSE        'f'
  594. #define K_FOR        'g'
  595. #define K_DO        'h'
  596. #define K_WHILE        'i'
  597. #define K_SWITCH    'j'
  598.  
  599. #define K_CASE        'k'
  600. #define K_DEFAULT    'l'
  601. #define K_ASM        'm'
  602.  
  603. #define K_SIZEOF    'n'
  604.  
  605. #else
  606. enum {
  607.     K_GOTO = 'a', K_RETURN, K_BREAK, K_CONTINUE,
  608.     K_IF, K_ELSE, K_FOR, K_DO, K_WHILE, K_SWITCH,
  609.     K_CASE, K_DEFAULT, K_ASM,
  610.     K_SIZEOF,
  611. };
  612. #endif
  613. SHAR_EOF
  614. cat << \SHAR_EOF > tok.h
  615. /* Copyright (c) 1988 by Sozobon, Limited.  Author: Johann Ruegg
  616.  *
  617.  * Permission is granted to anyone to use this software for any purpose
  618.  * on any computer system, and to redistribute it freely, with the
  619.  * following restrictions:
  620.  * 1) No charge may be made other than reasonable charges for reproduction.
  621.  * 2) Modified versions must be clearly marked as such.
  622.  * 3) The authors are not responsible for any harmful consequences
  623.  *    of using this software, even if they result from defects in it.
  624.  *
  625.  *    tok.h
  626.  *
  627.  *    establish token values
  628.  */
  629.  
  630. struct tok {
  631.     char    *name;
  632.     int    tnum;
  633.     long    ival;
  634.     double    fval;
  635.     char    prec;
  636.     int    flags;
  637. };
  638.  
  639. #include "flags.h"
  640. #include "bstok.h"
  641.  
  642. #define is_sclass(x)    (x >= K_EXTERN && x <= K_STATIC)
  643. #define is_tadj(x)    (x >= K_LONG && x <= K_UNSIGNED)
  644. #define is_btype(x)    (x >= K_INT && x <= K_VOID)
  645. #define is_tykw(x)    (x >= K_EXTERN && x <= K_STRUCT)
  646.  
  647. #define is_stkw(x)    (x >= K_GOTO && x <= K_ASM)
  648. #define is_brast(x)    (x >= K_GOTO && x <= K_CONTINUE)
  649. #define is_blkst(x)    (x >= K_IF && x <= K_SWITCH)
  650. #define is_lblst(x)    (x >= K_CASE && x <= K_DEFAULT)
  651.  
  652. #include "tytok.h"
  653. #include "sttok.h"
  654.  
  655. /* modifier seen flags */
  656. #define SAW_SHORT    1
  657. #define SAW_LONG    2
  658. #define SAW_UNS        4
  659. SHAR_EOF
  660. cat << \SHAR_EOF > tytok.h
  661. /* Copyright (c) 1988 by Sozobon, Limited.  Author: Johann Ruegg
  662.  *
  663.  * Permission is granted to anyone to use this software for any purpose
  664.  * on any computer system, and to redistribute it freely, with the
  665.  * following restrictions:
  666.  * 1) No charge may be made other than reasonable charges for reproduction.
  667.  * 2) Modified versions must be clearly marked as such.
  668.  * 3) The authors are not responsible for any harmful consequences
  669.  *    of using this software, even if they result from defects in it.
  670.  *
  671.  *    tytok.h
  672.  *
  673.  *    keyword token values
  674.  */
  675.  
  676. #ifndef ENUMS
  677. #define K_EXTERN    'A'
  678. #define K_AUTO        'B'
  679. #define K_REGISTER    'C'
  680. #define K_TYPEDEF    'D'
  681. #define K_STATIC    'E'
  682.  
  683. #define ENUM_SC        K_STATIC+1    /* storage class for enum item */
  684. #define HERE_SC        K_STATIC+2    /* storage class for glb def */
  685. #define FIRST_SC    K_EXTERN
  686. #define LAST_SC        K_STATIC
  687.  
  688. #define T_UCHAR        'F'
  689. #define T_ULONG        'G'
  690.  
  691. #define K_LONG        'H'
  692. #define K_SHORT        'I'
  693. #define K_UNSIGNED    'J'
  694.  
  695. #define K_INT        'K'
  696. #define K_CHAR        'L'
  697. #define K_FLOAT        'M'
  698. #define K_DOUBLE    'N'
  699. #define K_VOID        'O'
  700.  
  701. #define FIRST_BAS    T_UCHAR
  702. #define LAST_BAS    K_VOID
  703.  
  704. #define K_UNION        'P'
  705. #define K_ENUM        'Q'
  706. #define K_STRUCT    'R'
  707. #else
  708. #define FIRST_SC    K_EXTERN
  709. #define LAST_SC        K_STATIC
  710. #define FIRST_BAS    T_UCHAR
  711. #define LAST_BAS    K_VOID
  712. enum {
  713.     K_EXTERN = 'A', K_AUTO, K_REGISTER, K_TYPEDEF, K_STATIC,
  714.     ENUM_SC, HERE_SC,
  715.     T_UCHAR, T_ULONG,
  716.     K_LONG, K_SHORT, K_UNSIGNED,
  717.     K_INT, K_CHAR, K_FLOAT, K_DOUBLE, K_VOID,
  718.     K_UNION, K_ENUM, K_STRUCT
  719. };
  720. #endif
  721. SHAR_EOF
  722. cat << \SHAR_EOF > zc.doc
  723.  
  724.                                 ZC(1)
  725. ZC
  726. NAME
  727.    zc  -Sozobon C compiler ported to the amiga.  Ver 1.01
  728.     by  Johann Ruegg.
  729.     modified by Joe Montgomery Dec 1988.
  730.  
  731. SYNOPSIS
  732.    zc  [ options ] [file.c's ]
  733.  
  734. DESCRIPTION
  735.      Zc is a c compiler for the amiga.    It is as far as
  736.      I know a K & R compatible compiler.  Zc takes <file>.c
  737.      and creates a Motorola compatible assembly source whose
  738.      default name is <file>.s .  include files are looked
  739.      for in the directory specified by the manx environment
  740.      variable INCLUDE.    Simply use the command
  741.      set INCLUDE=includedir
  742.      from the CLI or place it in your startup-sequence.
  743.  
  744.      Below: are the options available at present.
  745.  
  746.        -Dxxxx    Define xxxx
  747.           same as a #define xxxx in the source file
  748.        -Uxxxx    Undefine xxxx
  749.           same as a #undefine xxxx in the source file
  750.        -Ixxxx    Include Directory = xxxx
  751.        -P    profiler. Places a call to mcount before calling
  752.           main.  You had better not use this for now.
  753.        -Oxxxx    outputfile name = xxxx
  754.        -V    display compiler version
  755.        -?    Help
  756.        -C    force Data,Bss into Chip memory
  757.        -F    force Data,Bss into Fast memory
  758.        -Exxxx    errorfile. Zc writes the number of errors into
  759.           this file.  This is used by the compiler front
  760.           end in order to determine whether to start the
  761.            assembler a68k.
  762.  
  763. BUGS
  764.  
  765.     See zc.readme.
  766.  
  767.  
  768.     Joe Montgomery UC Berkeley Math Dept.
  769.     monty@brahms.berkeley.edu
  770.  
  771.  
  772. SHAR_EOF
  773. cat << \SHAR_EOF > zcc.doc
  774.  
  775.                                 ZCC(1)
  776. ZCC
  777. NAME
  778.    zcc    A unix style front end for the
  779.     Sozobon C compiler(by Johann Ruegg) ported to the Amiga.  Ver 1.01
  780.     A68K  a Motorola Compatible 68000 Assembler for the Amiga.
  781.     Blink a Software Distillery Linker Ver 6.5 for the Amiga.
  782.  
  783. SYNOPSIS
  784.    zcc    [ options ] [file.c's ] [files.s] [files.o]
  785.  
  786. DESCRIPTION
  787.      Zcc is a unix style c front end for the Amiga.
  788.      It will compile all .c files creating .s files,
  789.      assemble all .s files creating .o files and link all
  790.      .o files creating an executable with the same name as
  791.      the first file minus the extension.
  792.  
  793.      Zcc will call zc to compile all .c files. If an error
  794.      occurs then zcc will abort and will not call the assembler
  795.      A68K or the linker Blink.    If a successful compile is
  796.      done then a68k is called and afterwards the .s file is
  797.      deleted. If all the files have been compiled and/or assembled
  798.      then Blink is called.
  799.  
  800.      Zcc will call a68k to assemble all .s files. The source will
  801.      not be deleted upon completion.
  802.  
  803.      Zcc looks to see if the following environment variables
  804.      have been set and if so then uses them otherwise default
  805.      directories will be used.
  806.  
  807.        Env Var         Default          Description
  808.     CCEXEC          c:        directory containing zc,a68k,blink
  809.     CCTEMP          ram:        location for temporay .s file
  810.                     only used for .c files which
  811.                     will be assembled.
  812.     INCLUDE             directory to find the include files
  813.     CCLIB          lib:        directory containing BothStartup.obj
  814.                     amiga.lib and any other libraries
  815.                     that will be used
  816.  
  817. OPTIONS
  818.          -Dxxxx   define xxxx
  819.          -Uxxxx   undefine xxxx
  820.          -C       data->chip
  821.          -F       data->fast
  822.          -S       don't use startups
  823.          -T       don't use amiga.lib
  824.          -A       don't assemble
  825.          -c       don't link
  826.          -Ixxxx   include dir
  827.          -V       printout actions only
  828.          -lxxxx   use library  CCLIBxxxx.lib
  829.  
  830. SEEALSO
  831.  
  832.    zc.doc
  833.  
  834. BUGS
  835.     See zc.readme.
  836.  
  837.  
  838.     Joe Montgomery UC Berkeley Math Dept.
  839.     monty@brahms.berkeley.edu
  840.  
  841.  
  842. SHAR_EOF
  843. cat << \SHAR_EOF > zc.readme
  844.       zc c - compiler
  845.  
  846.        revised by Joe Montgomery dec 1988.
  847.         (monty@brahms.berkeley.edu)
  848.  
  849.  
  850.     This is a modified version of hcc the Sozobon-C compiler by
  851.        Johann Ruegg.  The documentation released with the compiler
  852.        states the following:
  853.  
  854.  
  855.  * Permission is granted to anyone to use this software for any purpose
  856.  * on any computer system, and to redistribute it freely, with the
  857.  * following restrictions:
  858.  * 1) No charge may be made other than reasonable charges for reproduction.
  859.  * 2) Modified versions must be clearly marked as such.
  860.  * 3) The authors are not responsible for any harmful consequences
  861.  *    of using this software, even if they result from defects in it.
  862.  
  863.       I can only add that I can not be held responsible for any
  864.       harmful consequences as well.
  865.  
  866.      I hope that this goes a long way toward the goal of having a
  867.      freely distributable c compiler for the amiga.  I have modified
  868.      hcc so that it generates code compatible with a68k.  I have
  869.      not been able to test this adequately as I do not have the
  870.      amiga.lib.  However I will get it hopefully within a few weeks
  871.      and then begin to do some more checking.  It does seem to
  872.      to generate assembly language files that a68k does not complain
  873.      about.  There are some problems however:
  874.  
  875.     One I don't know Motorola 68000 assem or the directives.
  876.     A68k did not have much documentation so I guessed about
  877.     the use of some.  I used XREF for externally defined labels
  878.     XDEF for global defines, and DC,DS for data storage.  I hope
  879.     my usage is correct. Further a68k requires the SECTIONS DATA
  880.     and BSS to be named so I used DATA & BSS for those names.
  881.     This may be a problem or not. I do know that
  882.     hcc doesn't generate a XREF or public direc for functions
  883.     or variables which are external to the file.  It expects
  884.     the assembler to figure this out. a68k does not like this.
  885.     I tried to remedy both these problems to some extent.
  886.     The code has 0 comments and as I do not have a printer, I
  887.     found it difficult to make any major changes, so I caused
  888.     the compiler to generate a XREF label for every function
  889.     call. Not good, hopefully I can get that working latter.
  890.     For the variables, I was able to get it to generate XREF's
  891.     for externally defined global variables, however external
  892.     variables within a function are not declared to be XREF.
  893.  
  894.     I tried to label most of the changes I made with the
  895.     comment
  896.       /*  JMM ...
  897.  
  898.     The following files were modified:
  899.  
  900.     Revised main.c to use Amiga File System Naming Conventions
  901.        Added ?,C,F,E switches.
  902.                  ? help
  903.                  C force data,bss into Chip memory
  904.                  F force data,bss into Fast memory
  905.                  Exxxx use xxxx as errorfile.
  906.                    writes the number of errors to the
  907.                    file
  908.                  Oxxxx use xxxx as the output file
  909.                    instead of the default file.
  910.  
  911.     Revised out.c to use MOTOROLA assembly directives in order
  912.        to be compatible with C.Gibbs a68k assembler & blink
  913.        Added END statement
  914.        Changed .comm label,size to label DC.x 0
  915.            .even    to CNOP 2,0
  916.            .globl    to XDEF
  917.            .text    to CODE CODE  [CHIP | FAST]
  918.            .data    to DATA DATA  [CHIP | FAST]
  919.            .bss    to BSS BSS
  920.     Revised d2.c so that externs are declared as XREF -----
  921.     Revised g2.c & gen.c to declare all called functions XREF
  922.       (will need to change this to declare only external functions)
  923.  
  924.  
  925.      I also wrote a front end called zcc that automatically calls
  926.        a68k if no errors and then blink.
  927.      It is somewhat a unix style front end but I don't know all
  928.        the options available.
  929.  
  930.      for zcc and zc, if you type zcc ? or zc ? it will list the
  931.        various options.(one exception is that zc doesn't list
  932.             -E as an option.)
  933.  
  934.      Again, I hope to correct  the above problems as well as adding
  935.      more options.  One not of caution, zc expects all options
  936.      to be upper case. I did not change this as it uses all the
  937.      lower case options for debug purposes.  Perhaps in the future
  938.      I will change this.
  939.  
  940.      Please let me know of any problems, and I will attempt to fix
  941.      them.
  942.  
  943.  
  944.     Thanks, for all the great PD and FD software out there.  Hope
  945.     you can get some use out of this.
  946.  
  947.              Thanks again,
  948.  
  949.                Joe
  950.  
  951.  
  952.  
  953.  
  954.  
  955. SHAR_EOF
  956. cat << \SHAR_EOF > zcc.readme
  957. To create zcc simply compile and link zcc.c.
  958.       Note zcc.c is freely distributable.
  959.  
  960.     Joe Montgomery
  961.     monty@brahms.berkeley.edu
  962.  
  963.  
  964. SHAR_EOF
  965. cat << \SHAR_EOF > makefile
  966. OBJS =    d2.o decl.o expr.o fix.o fun.o g2.o gen.o gsub.o gunk.o \
  967.     main.o md.o nodes.o out.o p2.o pre.o tok.o subs.o
  968.  
  969. H =    bstok.h cookie.h flags.h gen.h nodes.h ops.h param.h \
  970.     sttok.h tok.h tytok.h
  971.  
  972. RM =        delete
  973. CFLAGS =    -c
  974. CC =        cc
  975. AFLAGS =    -o
  976. LD =        ln
  977. LDFLAGS =
  978. LIBS =        -lm32 -lc32
  979.  
  980. .c.o:
  981.     $(CC) $(CFLAGS)   $*.c
  982.  
  983.  
  984.  
  985. Zc :           $(OBJS)
  986.         $(LD) $(LDFLAGS) -o $@ $(OBJS) $(LIBS)
  987.  
  988. $(OBJS) :       $(H)
  989.  
  990. clean:
  991.         $(RM) *.o
  992.  
  993. clobber:
  994.         $(RM) *.o
  995.  
  996.  
  997.  
  998. SHAR_EOF
  999. cat << \SHAR_EOF > zcc.c
  1000. /*  preprocessor for zc (formerly hcc) , a68k assembler, blink
  1001. */
  1002.  
  1003.  
  1004. #include <stdio.h>
  1005.  
  1006. #define toupper( x ) ( x > 'Z' ? x - ('a'-'A'): x )
  1007.  
  1008. char *malloc();
  1009. extern char *getenv();
  1010.  
  1011.            /* flags if 1 then will allow that operation
  1012.         * to be performed on a file           */
  1013. short dozc,doa68k,doblink,dodebug,debug;
  1014. short blinkxref,startup,standardblinklib;
  1015.  
  1016. doexec( x,errmsg,file )
  1017. char x[],*errmsg,*file;
  1018. {
  1019. if( debug ){
  1020.   printf("%s\n",x);
  1021.   return(1);
  1022. }
  1023. if( ! Execute(x,0L,0L) ){
  1024.   printf(errmsg,file);
  1025.   quit();
  1026. }
  1027. return(1);
  1028. }
  1029.  
  1030. char libdir[32];          /* librarys' dir             */
  1031. char cmddir[32];         /*  zc,a68k,blink 's dir     */
  1032. char xrefname[128];        /* blink xref file output     */
  1033. char blinklibs[128];       /* blink lib direc        */
  1034. char blinkname[128];      /* output file from a68k     */
  1035. char a68kname[128];     /* output file from zc       */
  1036. char zcopts[128];    /* zc options for each phase */
  1037. char a68kopts[128];    /* a68k options            */
  1038. char zctemp[128];     /* CCTEMP dir           */
  1039. char blinkopts[128]; /* blink options          */
  1040. char buf[256];        /* command line         */
  1041. char buf2[256];    /* scratch buf        */
  1042.  
  1043. /* memory allocation/deallocation routines */
  1044. struct mem {
  1045. struct mem *prev;
  1046. long len;
  1047. char *memory;
  1048. } *curmem;
  1049.  
  1050.  
  1051. char *jmalloc(n)
  1052. long n;
  1053. {
  1054. char *buf;
  1055. struct mem *memlist;
  1056. buf=(char *)malloc( n+(long )sizeof(struct mem));
  1057. if(!buf){
  1058.     printf("cc: outofmemory\n");
  1059.     quit();
  1060. }
  1061. memlist=(struct mem *)buf;
  1062. memlist->len=n;
  1063. memlist->memory=buf+sizeof(struct mem);
  1064. memlist->prev=curmem;
  1065. curmem=memlist;
  1066. return(memlist->memory);
  1067. }
  1068.  
  1069. quit()
  1070. {
  1071.  
  1072.   jfree();
  1073.   exit(0);
  1074. }
  1075.  
  1076. jfree(){
  1077. struct mem *nxmem;
  1078.  
  1079. while(curmem != NULL){
  1080.   nxmem=curmem->prev;
  1081.   free(curmem);  /* frees all the memory we so graciously gobbled up */
  1082.   curmem=nxmem;
  1083. }
  1084. }/*end of jfree */
  1085.  
  1086.  
  1087.  
  1088. /*********************************************************
  1089.  
  1090.   Handles file list compiles,assembles,links
  1091.  
  1092. **********************************************************/
  1093.  
  1094.  
  1095. /* lists of source file names, as well as type of operation */
  1096.  
  1097. struct filenm{
  1098.   struct filenm *next;
  1099.   struct filenm *prev;
  1100.   short ab;     /* abnormal file name */
  1101.   short zc;      /* 1 if .c file */
  1102.   short a68k;      /* 1 if .s file */
  1103.   char *name;
  1104. }*files,*curfile;
  1105.  
  1106.  
  1107. #define copystring( x )  (char *)strcpy( jmalloc( (long )len((char *) x )), x )
  1108.  
  1109.  
  1110. /* adds a file to the file list
  1111.  *   computes whether an compile and/or assembly will be done
  1112.  *   also determines whether this is an abnormal file name.
  1113.  *   If so then only a link will be done on the file
  1114.  */
  1115. struct filenm *addfile(name)
  1116. char name[];
  1117. {
  1118. long l;
  1119. struct filenm *newfile;
  1120. char *filename;
  1121.  
  1122. newfile = (struct filenm *)jmalloc(sizeof(struct filenm));
  1123. newfile->prev = curfile;
  1124. newfile->next = NULL; /* last file so far */
  1125. if(curfile)
  1126.    curfile->next = newfile;
  1127. else
  1128.    files = newfile;
  1129. curfile = newfile;
  1130. filename = (char *) copystring( (char *)name);
  1131. curfile->name=filename;    /* contains the new filename */
  1132. l=len(filename);
  1133.  
  1134. curfile->ab=0; /* assume it is normal until proven otherwise */
  1135. curfile->zc=0;
  1136. curfile->a68k=0;
  1137.  
  1138. if(filename[l-2] == '.'){
  1139.   if(filename[l-1]== 'c'){
  1140.      curfile->zc = 1;
  1141.      curfile->a68k=1;
  1142.   }else if (filename[l-1] == 'a' || filename[l-1] == 's'){
  1143.      curfile->a68k=1;
  1144.   }else if(filename[l-1] != 'o')
  1145.      curfile->ab = 1; /* abnormal file name */
  1146. }else
  1147.   curfile->ab = 1; /* abnormal file name */
  1148. }/* end of addfile */
  1149.  
  1150.  
  1151.  
  1152. long len(x)
  1153. char x[];
  1154. {
  1155. long i;
  1156.  
  1157. for(i=0; x[i] != 0 ; i++);
  1158. return(i);
  1159. }
  1160.  
  1161.  
  1162.  
  1163.  
  1164. char *tofiletype(nm,buffer,ext1,ext2)
  1165. char nm[],buffer[],ext1[],ext2;
  1166. {
  1167. long l;
  1168.  
  1169. strcpy(buffer,nm);
  1170. l=len(buffer);
  1171. if(l < 2 || ( buffer[l-2] != '.') ){
  1172.   strcat(buffer,ext1);
  1173.   return(buffer);
  1174. }
  1175. if(ext2)
  1176.   buffer[l-1] = ext2;
  1177. else
  1178.   buffer[l-2] = '\0'; /* must be executable */
  1179. return(buffer);
  1180. }/*end of tofiletype */
  1181.  
  1182. #define toassem( x ) tofiletype( x ,a68kname,".s ",'s')
  1183. #define tolink( x ) tofiletype( x ,blinkname,".o ",'o')
  1184. #define toexec( x ) tofiletype( x ,blinkname,".lnk ",'\0')
  1185.  
  1186. doerrors()
  1187. {
  1188. FILE *err;
  1189. int nmerrors;
  1190.  
  1191.   if( (err=fopen("ram:zc.errors","r"))==NULL)
  1192.      return();
  1193.   nmerrors=0;
  1194.   fscanf(err,"%d",&nmerrors);
  1195.   close(err);
  1196.   if(nmerrors)
  1197.      quit();
  1198.   return(); /* no errors thank goodness */
  1199. }
  1200.  
  1201.  
  1202. /* this assembles the file */
  1203. assemfile(nm,outnm)
  1204. char nm[],outnm[];
  1205. {
  1206.  
  1207. strcpy(buf,cmddir);
  1208. strcat(buf,"a68k <* >* ");
  1209. strcat(buf,a68kopts);
  1210. strcat(buf,"-o");
  1211. strcat(buf,outnm);
  1212. strcat(buf," ");
  1213. strcat(buf,nm);
  1214. Chk_Abort();
  1215. doexec(buf,"cc: assemble error: %s\n",nm);
  1216. }/*end of assemfile*/
  1217.  
  1218. /* compiles and/or assembles the files in the file list */
  1219. compilefiles(){
  1220. struct filenm *file;
  1221. char nm[];
  1222.  
  1223. file=files;
  1224. while(file){
  1225.   toassem(file->name);/* use this as the input to a68k
  1226.                * unless updated below           */
  1227.   if(file->zc && dozc ){
  1228.      strcpy(buf,cmddir);
  1229.      strcat(buf,"zc >* <* -Eram:zc.errors ");
  1230.      strcat(buf,zcopts);
  1231.      strcat(buf," ");
  1232.      if( (file->a68k && doa68k) || file->ab){
  1233.        strcat(buf," -O");
  1234.        if(file->a68k && doa68k)
  1235.      strcpy(buf2,zctemp);  /* use temp file if doing an assemble */
  1236.        else
  1237.      buf2[0]='\0';
  1238.        strcat(buf2,file->name);
  1239.        strcat(buf,toassem(buf2));/* use designated outputfile */
  1240.      }
  1241.      strcat(buf," ");
  1242.      strcat(buf,file->name);
  1243.      Chk_Abort();
  1244.      doexec(buf,"cc: compile error: %s\n",file->name);/* start compiler */
  1245.      doerrors(); /* read error file to see if any errors */
  1246.   }   /* compiled okay */
  1247.   if(file->a68k && doa68k){
  1248.      assemfile(a68kname,tolink(file->name)); /* assemble file */
  1249.      if(file->zc){ /* if was a c file remove .s file */
  1250.        strcpy(buf,"c:delete >* <* ");
  1251.        strcat(buf,a68kname);
  1252.        Chk_Abort();
  1253.        doexec(buf,"cc: delete error: %s\n",a68kname);
  1254.      }
  1255.   }
  1256.   file=file->next;/* get next file */
  1257. }/* done with this file, compile & assemble next */
  1258. }/* done with files */
  1259.  
  1260.  
  1261. linkfiles(){
  1262. struct filenm *file;
  1263. char nm[];
  1264.  
  1265. if(!doblink || files == NULL ) return();/* don't do anything if not supposed to */
  1266. file=files;
  1267. strcpy(buf,cmddir);
  1268. strcat(buf,"blink <* >* ");
  1269. if(startup){
  1270.   strcat(buf,libdir);
  1271.   strcat(buf,"BothStartup.obj ");
  1272. }
  1273. while(file){
  1274.   strcat(buf,tolink(file->name));/* build linker list */
  1275.   file = file->next;
  1276.   strcat(buf," ");
  1277. }
  1278. strcat(buf," TO ");
  1279. strcat(buf,toexec(files->name));/* use first file name */
  1280. strcat(buf," LIB ");
  1281. strcat(buf,blinklibs);
  1282. if(standardblinklib){
  1283.    strcat(buf,libdir);
  1284.    strcat(buf,"amiga.lib ");
  1285. }
  1286. if(!dodebug)
  1287.   strcat(buf," NODEBUG ");
  1288. if(blinkxref){
  1289.   strcat(buf," XREF ");
  1290.   strcat(buf,xrefname);
  1291. }
  1292. Chk_Abort();
  1293. doexec(buf,"cc: linker error:\n",NULL);
  1294. printf("cc: executable is %s \n",toexec(files->name));
  1295. }/* done linking it */
  1296.  
  1297.  
  1298. help()
  1299. {
  1300.  
  1301.   printf("cc: Version 1.0 Preprocessor for \n%s%s%s%s%s%s%s%s%s%s%s%s%s",
  1302.      "   cc: Sozobon-C compiler, \n",
  1303.      "   as: a68k C.Gibbs Motorola Compatible Assembler, and\n",
  1304.      "   blink:  Software Distillery Linker \n",
  1305.      "           looks for lib:amiga.lib and lib:BothStartup.obj \n",
  1306.      "   Syntax:\n",
  1307.      "           cc [OPTIONS] <files.c> <files.s> <files.o> \n\n",
  1308.      "   Options:\n",
  1309.      "    -Dxxxx   define xxxx,   -Uxxxx undefine xxxx\n",
  1310.      "    -C    data->chip,       -F data->fast\n",
  1311.      "    -S  don't use startups, -T don't use amiga.lib\n",
  1312.      "    -A    don't assemble,   -c don't link\n",
  1313.      "    -Ixxxx  include dir,    -V printout actions only\n",
  1314.      "    -lxxxx  use library  lib:xxxx.lib\n");
  1315. }
  1316.  
  1317. main(argc,argv)
  1318. int argc;
  1319. char *argv[];
  1320. {
  1321.   int i, l;
  1322.   char *s;
  1323.  
  1324.   printf("cc: \n");
  1325.   if(argc < 2 || argv[1][0] == '?'){
  1326.      help();
  1327.      exit(0);
  1328.   }
  1329.   startup=standardblinklib=1;/* use BothStartup.obj & amiga.lib */
  1330.   blinklibs[0]='\0';       /* blink lib direc           */
  1331.   blinkname[0]='\0';      /* output file from a68k     */
  1332.   a68kname[0]='\0';      /* output file from zc       */
  1333.   zcopts[0]='\0';       /* zc options for each phase */
  1334.   a68kopts[0]='\0';    /* a68k options              */
  1335.   zctemp[0]='\0';     /* CCTEMP dir                */
  1336.   blinkopts[0]='\0'; /* blink options             */
  1337.   buf[0]='\0';      /* command line              */
  1338.   buf2[0]='\0';    /* scratch buf               */
  1339.  
  1340.   dodebug=debug=0;
  1341.   dozc=doa68k=doblink=1;/* will compile,assem,link unless told otherwise*/
  1342.   curmem=NULL;/* haven't grabbed any memory yet*/
  1343.   files=NULL;
  1344.   curfile=NULL;
  1345.   blinkxref=0;
  1346.   strcpy(xrefname," ");
  1347.  
  1348.   if( getenv("CCLIB") ){
  1349.       strcpy(libdir," ");
  1350.       strcat(libdir,getenv("CCLIB")); /* get libdirector */
  1351.   }else
  1352.       strcpy(libdir," lib:"); /* default directory */
  1353.   if( ! getenv("CCEXEC") )
  1354.       strcpy(cmddir,"c:");
  1355.   else{
  1356.       strcpy(cmddir,getenv("CCEXEC")); /*dir for zc,a68k,blink */
  1357.   }
  1358.   if( getenv("CCTEMP") ){
  1359.      strcpy(zctemp,getenv("CCTEMP"));
  1360.   }else{
  1361.      printf("cc:Warning, environment variable CCTEMP unset\n   Using ram: \n");
  1362.      strcpy(zctemp,"ram:");
  1363.   }
  1364.   if( ! getenv("INCLUDE")){
  1365.      printf("cc: Warning, environment variable INCLUDE unset\n");
  1366.   }else{
  1367.      strcpy(a68kopts," -I");
  1368.      strcat(a68kopts,getenv("INCLUDE") );
  1369.   }
  1370.   for(i = 1; i < argc; i++){/* parse arguments */
  1371.      Chk_Abort();  /* Do options */
  1372.      if(argv[i][0] == '+'){
  1373.     s = argv[i];
  1374.     switch(s[1]){
  1375.        default:
  1376.           printf("cc: No + switches allowed\n");
  1377.           break;
  1378.     }
  1379.       }else if(argv[i][0] == '-' ){
  1380.     s = argv[i];
  1381.     switch(s[1]){
  1382.        case 'A':
  1383.        case 'a':
  1384.          doblink = doa68k = 0;
  1385.          break;
  1386.        case 'C':  /* force data into chip memory */
  1387.          strcat(zcopts," -C ");
  1388.          break;
  1389.        case 'c':
  1390.          doblink = 0;
  1391.          break;
  1392.        case 'd':
  1393.        case 'D':
  1394.          strcat(zcopts," -D");
  1395.          strcat(zcopts,&s[2]);
  1396.          break;
  1397.        case 'F':
  1398.          strcat(zcopts," -F ");
  1399.          break;
  1400.        case 'i':
  1401.        case 'I':
  1402.          strcat(zcopts," -I");
  1403.          strcat(zcopts,&s[2]);
  1404.          break;
  1405.        case 'l':
  1406.          strcat(blinklibs," -l");
  1407.          strcat(blinklibs,&s[2]);
  1408.          strcat(blinklibs," ");
  1409.          break;
  1410.        case 'T':
  1411.          standardblinklib=0; /* don't use amiga.lib */
  1412.          break;
  1413.        case 'S':
  1414.          startup = 0;/* don't use BothStartup.obj */
  1415.          break;
  1416.        case 'u':
  1417.        case 'U':
  1418.          strcat(zcopts," -U");
  1419.          strcat(zcopts,&s[2]);
  1420.          break;
  1421.        case 'v':
  1422.        case 'V':
  1423.          debug = 1;
  1424.          break;
  1425.        default:
  1426.          printf("bad option: \"%s\"\n", argv[i]);
  1427.          exit(1);
  1428.          break;
  1429.     }
  1430.      }else  /* argument wasn't an option so must be a file  */
  1431.     addfile(argv[i]);/* add filename to list of files */
  1432.   }/* done with parsing arguments */
  1433.   compilefiles(); /* compile all the files */
  1434.   linkfiles();   /*  link all the files */
  1435.   quit();/* cleanup mess and go home */
  1436. }
  1437.  
  1438. SHAR_EOF
  1439. #    End of shell archive
  1440. exit 0
  1441. -- 
  1442. Bob Page, U of Lowell CS Dept.  page@swan.ulowell.edu  ulowell!page
  1443. Have five nice days.
  1444.